package com.gem.service.impl;

import com.gem.entity.Customer;
import com.gem.mapper.CustomerMapper;
import com.gem.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author zhang
 * @date 2020/10/4 15:39
 */
@Service
public class CustomerServiceImpl implements CustomerService {

    @Autowired
    CustomerMapper customerMapper;

    @Override
    public int register(String username, String password) {
        Customer customer = new Customer();
        customer.setUsername(username);
        customer.setPassword(password);
        int i = customerMapper.insertCustomer(customer);
        return i;
    }

    @Override
    public void eidtCustomer(Customer customer) {
        customerMapper.updateCustomer(customer);
    }

    @Override
    public Customer login(String username, String password) {
        return customerMapper.selectCustomerByUsernameAndPassword(username,password);
    }

    @Override
    public Boolean checkUsername(String username) {
        Customer customer = customerMapper.selectCustomerByUsername(username);
        if (customer == null){
            return true;
        }
        return false;
    }

    @Override
    public Customer findCustomerById(int id) {
        return customerMapper.selectCustomerById(id);
    }
}
